#include "defs.h"
#include "helper.h"

void Helper_T::GetServerVariable
(
	PHTTP_FILTER_CONTEXT pFC, 
	char * nameBuffer, 
	char * valueBuffer, 
	int * lengthPtr
)
{
	if( !pFC->GetServerVariable(pFC, nameBuffer, valueBuffer, (DWORD *)lengthPtr) )
	{
		if( ERROR_INVALID_INDEX != GetLastError() )
		{
			throw Exception_T(GetLastError(), __FILE__, __LINE__, __FUNCSIG__,
				"Unable to get server variable '%s'", nameBuffer);
		}
	}
}

void Helper_T::GetHeader
(
	PHTTP_FILTER_CONTEXT pFC, 
	GetHeaderFn_T GetHeaderFn,
	char * nameBuffer, 
	char * valueBuffer, 
	int * lengthPtr
)
{
	if( !GetHeaderFn(pFC, nameBuffer, valueBuffer, (DWORD *)lengthPtr) )
	{
		if( ERROR_INVALID_INDEX != GetLastError() )
		{
			throw Exception_T(GetLastError(), __FILE__, __LINE__, __FUNCSIG__,
				"Unable to get header '%s'", nameBuffer);
		}
	}
}

void Helper_T::SetHeader
(
	PHTTP_FILTER_CONTEXT pFC, 
	SetHeaderFn_T SetHeaderFn,
	char * nameBuffer, 
	char * valueBuffer
)
{
	if( !SetHeaderFn(pFC, nameBuffer, valueBuffer) )
	{
		throw Exception_T(GetLastError(), __FILE__, __LINE__, __FUNCSIG__,
				"Unable to set header '%s' equal to '%s'", nameBuffer, valueBuffer);
	}
}

void Helper_T::AddHeader
(
	PHTTP_FILTER_CONTEXT pFC, 
	AddHeaderFn_T AddHeaderFn,
	char * nameBuffer, 
	char * valueBuffer
)
{
	if( !AddHeaderFn(pFC, nameBuffer, valueBuffer) )
	{
		throw Exception_T(GetLastError(), __FILE__, __LINE__, __FUNCSIG__,
			"Unable to add header '%s' equal to '%s'", nameBuffer, valueBuffer);
	}
}
